using System;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

namespace YourCompany.Modules.Cafeteria
{
	public partial class EditCafeteria : PortalModuleBase
	{

		int itemId = Null.NullInteger;

		protected void Page_Load(object sender, EventArgs e)
		{
			try
			{
			}
			catch (Exception ex)
			{
				Exceptions.ProcessModuleLoadException(this, ex);
			}
		}

		protected void cmdCancel_Click(object sender, EventArgs e)
		{
			try
			{
				Response.Redirect(Globals.NavigateURL(), true);
			}
			catch (Exception ex)
			{
				Exceptions.ProcessModuleLoadException(this, ex);
			}
		}

		protected void Button1_Click(object sender, EventArgs e)
		{
			int i;
			TitleError.Text = " ";
			DetailError.Text = " ";
			ProductPriceError.Text = " ";
			ProductIDError.Text = " ";
			ProductQuantityError.Text = " ";
			Label6.Text = " ";
			Label7.Text = " ";
			if ((TextBox2.Text == "") || (int.TryParse(TextBox2.Text.Trim(), out i) == false))
			{
				ProductPriceError.Text = "Wrong Product Price !!";
			}
			if ((TextBox2.Text != "") && (int.TryParse(TextBox2.Text.Trim(), out i) == true))
			{
				CafeteriaController cntrlr = new CafeteriaController();

				if (Convert.ToInt32(TextBox2.Text) < 0)
				{
					ProductPriceError.Text = "Wrong Product Price !!";
				}
				if (Convert.ToInt32(TextBox2.Text) >= 0)
				{
					Cafeteria cafeteria = new Cafeteria();
					cafeteria.ItemName = TextBox1.Text;
					cafeteria.ItemPrice = Convert.ToInt32(TextBox2.Text);

					cntrlr.AddCafeteria(cafeteria);
					TextBox1.Text = "";
					TextBox2.Text = "";
				}

				this.GridView1.DataBind();
				this.GridView2.DataBind();
				this.GridView3.DataBind();
			}
		}

		protected void Button2_Click(object sender, EventArgs e)
		{
			int i;
			TitleError.Text = " ";
			DetailError.Text = " ";
			ProductPriceError.Text = " ";
			ProductIDError.Text = " ";
			ProductQuantityError.Text = " ";
			Label6.Text = " ";
			Label7.Text = " ";
			if ((TextBox3.Text == "") || (int.TryParse(TextBox3.Text.Trim(), out i) == false))
			{
				ProductIDError.Text = "Wrong Product ID !!";
			}
			if ((TextBox4.Text == "") || (int.TryParse(TextBox4.Text.Trim(), out i) == false))
			{
				ProductQuantityError.Text = "Wrong Product Quantity !!";
			}
			if ((TextBox3.Text != "") && (TextBox4.Text != "") && (int.TryParse(TextBox3.Text.Trim(), out i) == true) && (int.TryParse(TextBox4.Text.Trim(), out i) == true))
			{
				CafeteriaOrderController cntrlr = new CafeteriaOrderController();
				CafeteriaController cntrlr1 = new CafeteriaController();

				Cafeteria cafeteria = new Cafeteria();
				cafeteria.ItemID = Convert.ToInt32(TextBox3.Text);

				if (cntrlr1.GetCafeteria(cafeteria.ItemID) == null)
				{
					ProductIDError.Text = "Wrong Product ID !!";
				}
				if (cntrlr1.GetCafeteria(cafeteria.ItemID) != null)
				{
					CafeteriaOrder cafeteriaOrder = new CafeteriaOrder();
					cafeteriaOrder.ItemID = Convert.ToInt32(TextBox3.Text);
					cafeteriaOrder.ItemQuantity = Convert.ToInt32(TextBox4.Text);
					cafeteriaOrder.Room = TextBox5.Text;
					cafeteriaOrder.TotalPrice = cntrlr1.GetCafeteria(cafeteria.ItemID).ItemPrice * Convert.ToInt32(TextBox4.Text);

					Label6.Text = cafeteriaOrder.TotalPrice.ToString() + " VND";
				}

				this.GridView1.DataBind();
				this.GridView2.DataBind();
				this.GridView3.DataBind();
			}
		}

		protected void Button3_Click(object sender, EventArgs e)
		{
			int i;
			TitleError.Text = " ";
			DetailError.Text = " ";
			ProductPriceError.Text = " ";
			ProductIDError.Text = " ";
			ProductQuantityError.Text = " ";
			Label6.Text = " ";
			Label7.Text = " ";
			if ((TextBox3.Text == "") || (int.TryParse(TextBox3.Text.Trim(), out i) == false))
			{
				ProductIDError.Text = "Wrong Product ID !!";
			}
			if ((TextBox4.Text == "") || (int.TryParse(TextBox4.Text.Trim(), out i) == false))
			{
				ProductQuantityError.Text = "Wrong Product Quantity !!";
			}
			if ((TextBox3.Text != "") && (TextBox4.Text != "") && (int.TryParse(TextBox3.Text.Trim(), out i) == true) && (int.TryParse(TextBox4.Text.Trim(), out i) == true))
			{
				CafeteriaOrderController cntrlr = new CafeteriaOrderController();
				CafeteriaController cntrlr1 = new CafeteriaController();

				Cafeteria cafeteria = new Cafeteria();
				cafeteria.ItemID = Convert.ToInt32(TextBox3.Text);

				if (cntrlr1.GetCafeteria(cafeteria.ItemID) == null)
				{
					ProductIDError.Text = "Wrong Product ID !!";
				}
				if (cntrlr1.GetCafeteria(cafeteria.ItemID) != null)
				{
					CafeteriaOrder cafeteriaOrder = new CafeteriaOrder();
					cafeteriaOrder.ItemID = Convert.ToInt32(TextBox3.Text);
					cafeteriaOrder.ItemQuantity = Convert.ToInt32(TextBox4.Text);
					cafeteriaOrder.Room = TextBox5.Text;
					cafeteriaOrder.TotalPrice = cntrlr1.GetCafeteria(cafeteria.ItemID).ItemPrice * Convert.ToInt32(TextBox4.Text);

					cafeteriaOrder.Time = DateTime.Now;
					cafeteriaOrder.ByUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().DisplayName;

					cntrlr.AddOrder(cafeteriaOrder);
					TextBox3.Text = "";
					TextBox4.Text = "";
					TextBox5.Text = "";
					Label6.Text = " ";

					Label7.Text = "Order Online Succeed !";
				}

				this.GridView1.DataBind();
				this.GridView2.DataBind();
				this.GridView3.DataBind();
			}
		}

		protected void Button4_Click(object sender, EventArgs e)
		{
			TitleError.Text = " ";
			DetailError.Text = " ";
			ProductPriceError.Text = " ";
			ProductIDError.Text = " ";
			ProductQuantityError.Text = " ";
			Label6.Text = " ";
			Label7.Text = " ";
			if (TextBox6.Text == "")
			{
				TitleError.Text = "Empty Title !!";
			}
			if (TextBox7.Text == "")
			{
				DetailError.Text = "Empty Detail !!";
			}
			if ((TextBox6.Text != "") && (TextBox7.Text != ""))
			{
				AnnouncementController cntrlr = new AnnouncementController();

				Announcement announcement = new Announcement();
				announcement.Time = DateTime.Now;
				announcement.Title = TextBox6.Text;
				announcement.Detail = TextBox7.Text;

				cntrlr.AddAnnouncement(announcement);
				TextBox6.Text = "";
				TextBox7.Text = "";

				this.GridView1.DataBind();
				this.GridView2.DataBind();
				this.GridView3.DataBind();
			}
		}
	}
}
